package com.bdy.lm.taximanager;

import android.app.Application;
import android.location.Address;
import android.location.Geocoder;
import android.test.ApplicationTestCase;
import android.util.Log;

import com.bdy.lm.taximanager.model.StandardRoute;
import com.bdy.lm.taximanager.util.JsonUtils;
import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
 * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
 */
public class ApplicationTest extends ApplicationTestCase<Application> {
    public ApplicationTest() {
        super(Application.class);
//        Map<String, Object> am = new HashMap<>();
//        A a = new A("a");
//        am.put("a", a);
//        JSONObject jo = JsonUtils.mapToJsonObject(am);
//        try {
//            String aa = (String)jo.get("a");
//            System.out.println("jjjjjjjjjjjjj"+jo.toString());
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }
//
//        String TAG = "turn";
//        Geocoder gc = new Geocoder(getSystemContext(), Locale.getDefault());
//        List<Address> locationList = null;
//        try {
//            locationList = gc.getFromLocation(26.0724456, 119.24798, 1);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        Address address = locationList.get(0);//得到Address实例
//        Log.i(TAG, "address =" + address);
//        String countryName = address.getCountryName();//得到国家名称，比如：中国
//        Log.i(TAG, "countryName = " + countryName);
//        String locality = address.getLocality();//得到城市名称，比如：北京市
//        Log.i(TAG, "locality = " + locality);
//        for (int i = 0; address.getAddressLine(i) != null; i++) {
//            String addressLine = address.getAddressLine(i);//得到周边信息，包括街道等，i=0，得到街道名称
//            Log.i(TAG, "addressLine = " + addressLine);
//        }

        String j = "{\"flagBitBegin\":126,\"messageID\":113,\"messageSize\":15,\"ISUFlag_1\":0,\"ISUFlag_company_2\":0,\"ISUFlag_device_3\":0,\"ISUFlag_serialNum_4\":0,\"messageSerialNum\":3,\"checkCode\":-34,\"flagBitEnd\":126,\"ISUFlag\":\"1616010526880\",\"ICID\":\"195996CE\",\"reportTime\":\"1513241247273\",\"runState\":\"none\",\"status_1\":0,\"status_2\":0,\"status_3\":0,\"status_4\":0,\"alarm_byte_1\":0,\"alarm_byte_2\":0,\"alarm_byte_3\":0,\"alarm_byte_4\":0,\"latitude\":0.0,\"longitude\":0.0,\"speed\":0.0,\"direction\":0.0,\"standardRoutes\":[{\"num\":1000002,\"Alongitude\":116.28748,\"Alatitude\":39.842518,\"Aaltitude\":11.0,\"Aradius\":10.0,\"Blongtitde\":116.287323,\"Blatitude\":39.845862,\"Baltitude\":11.0,\"Bradius\":10.0,\"Smeasure\":12.0,\"standard\":32.0}]}";
        try {
            JSONObject js = new JSONObject(j);
            JSONArray ja = js.getJSONArray("standardRoutes");
            System.out.println(ja.length());
            System.out.println(new Gson().fromJson(ja.get(0).toString(), StandardRoute.class));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    class A{
        String a;
        public A(String a){
            this.a = a;
        }
    }
}